
#include "game.h"
void menu()
{
    printf("\n");
    printf("\n");
    printf("***************************************\n");
    printf("*********  1 . play  ******************\n");
    printf("*********  0 . exit  ******************\n");
    printf("***************************************\n\n");
}

void game()
{
    char board[ROW][COL] = {0};
    char res = 0;
    // 初始化棋盘
    InitBoard(board, ROW, ROW);
    DisplayBoard(board, ROW, COL);
    while (1)
    {
        // return *  玩家赢了
        // return #  电脑赢了
        // return c 继续
        // retuen q  平局，退出
        // 玩家下棋
        // 要么玩家赢 要么电脑赢 要么棋盘满了平局  要么继续下
        // 玩家下棋
        PlayerMove(board, ROW, COL);
        // 判断输赢
        res = IsWin(board, ROW, COL); // 玩家赢   电脑赢  平局(棋盘满了)   继续下
        if (res != 'c')
        {
            break;
        }
        // 展示棋盘
        printf("now is\n");

        DisplayBoard(board, ROW, COL);
        // 电脑下棋
        ComputerMove(board, ROW, COL);
        printf("now is\n");
        // 展示棋盘
        DisplayBoard(board, ROW, COL);
        res = IsWin(board, ROW, COL); // 玩家赢   电脑赢  平局(棋盘满了)    继续下
        if (res != 'c')
        {
            break;
        }
    }
    if (res == '*')
    {
        printf("-------------------------------------------------------------------- you have won\n now is \n");
    }
    else if (res == '#')
    {
        printf("-------------------------------------------------------------------- the computer has won\n now is \n");
    }
    else
    {
        printf("-------------------------------------------------------------------- it is a draw\n now is \n");
    }
    DisplayBoard(board, ROW, COL);
}
int main()
{
    srand((unsigned int)time(NULL));
    int input = 0;
    /* menu(); */
    do
    {
        menu();

        printf("chose one option  \n\n 0 or 1 \n-->");
        scanf("%d", &input);
        switch (input)
        {
        case 0:
            printf("exit\n");
            system("pause");
            break;
        case 1:
            printf("play chess\n");
            // printf("下棋");
            game();
            break;
        default:
            printf("<<  chose error  >>\n");
            // printf("<<  选择错误  >>\n");

            break;
        }
    } while (input);

    return 0;
}